﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SLControlLibrary.Resources.Controls.Calendar.OutlookCalendar.BusinessObjects;
using SLControlLibrary.Resources.Controls.Calendar.OutlookCalendar.DataAccess;
using SLControlLibrary.Resources.Controls.Calendar.OutlookCalendar.Common;

namespace SLControlLibrary.Resources.Controls.Calendar.OutlookCalendar
{
    public class ucTimeSlots : ItemsControl
    {
        #region Dependency Variables
        private static readonly DependencyProperty ContentBackgroundProperty = DependencyProperty.Register("ContentBackground", typeof(Brush), typeof(ucTimeSlots), new PropertyMetadata(SLControlLibrary.Resources.Common.Utility.ConvertStringToColor("#F0F1F2"), new PropertyChangedCallback(ContentBackground_Changed)));
        private static readonly DependencyProperty ContentBorderBrushProperty = DependencyProperty.Register("ContentBorderBrush", typeof(Brush), typeof(ucTimeSlots), new PropertyMetadata(SLControlLibrary.Resources.Common.Utility.ConvertStringToColor("#4C535C"), new PropertyChangedCallback(ContentBorderBrush_Changed)));
        private static readonly DependencyProperty ContentBorderThicknessProperty = DependencyProperty.Register("ContentBorderThickness", typeof(Thickness), typeof(ucTimeSlots), new PropertyMetadata(new Thickness(0, 0, 0, 1), new PropertyChangedCallback(ContentBorderThickness_Changed)));
        private static readonly DependencyProperty CurrentTimeBackgroundProperty = DependencyProperty.Register("CurrentTimeBackground", typeof(Brush), typeof(ucTimeSlots), new PropertyMetadata(SLControlLibrary.Resources.Common.Utility.ConvertStringToColor("#F3E4C1"), new PropertyChangedCallback(CurrentTimeBackground_Changed)));
        private static readonly DependencyProperty CurrentTimeBorderBrushProperty = DependencyProperty.Register("CurrentTimeBorderBrush", typeof(Brush), typeof(ucTimeSlots), new PropertyMetadata(SLControlLibrary.Resources.Common.Utility.ConvertStringToColor("#BB5503"), new PropertyChangedCallback(CurrentTimeBorderBrush_Changed)));
        private static readonly DependencyProperty CurrentTimeBorderThicknessProperty = DependencyProperty.Register("CurrentTimeBorderThickness", typeof(Thickness), typeof(ucTimeSlots), new PropertyMetadata(new Thickness(0, 1, 0, 1), new PropertyChangedCallback(CurrentTimeBorderThickness_Changed)));
        public static readonly DependencyProperty TimeSlotsPerHourProperty = DependencyProperty.Register("TimeSlotsPerHour", typeof(SLControlLibrary.Resources.Common.Enumerations.TimeSlotsPerHour), typeof(ucTimeSlots), new PropertyMetadata(SLControlLibrary.Resources.Common.Enumerations.TimeSlotsPerHour.Fifteen, new PropertyChangedCallback(TimeSlotsPerHour_Changed)));
        public static readonly DependencyProperty HoursPerDayProperty = DependencyProperty.Register("HoursPerDay", typeof(SLControlLibrary.Resources.Common.Enumerations.HoursPerDay), typeof(ucTimeSlots), new PropertyMetadata(SLControlLibrary.Resources.Common.Enumerations.HoursPerDay.TwentyFour, new PropertyChangedCallback(HoursPerDay_Changed)));
        #endregion

        #region Dependency Properties
        public Brush ContentBackground
        {
            get { return (Brush)this.GetValue(ContentBackgroundProperty); }
            set { SetValue(ContentBackgroundProperty, value); }
        }
        public Brush ContentBorderBrush
        {
            get { return (Brush)this.GetValue(ContentBorderBrushProperty); }
            set { SetValue(ContentBorderBrushProperty, value); }
        }
        public Thickness ContentBorderThickness
        {
            get { return (Thickness)this.GetValue(ContentBorderThicknessProperty); }
            set { SetValue(ContentBorderThicknessProperty, value); }
        }
        public Brush CurrentTimeBackground
        {
            get { return (Brush)this.GetValue(CurrentTimeBackgroundProperty); }
            set { SetValue(CurrentTimeBackgroundProperty, value); }
        }
        public Brush CurrentTimeBorderBrush
        {
            get { return (Brush)this.GetValue(CurrentTimeBorderBrushProperty); }
            set { SetValue(CurrentTimeBorderBrushProperty, value); }
        }
        public Thickness CurrentTimeBorderThickness
        {
            get { return (Thickness)this.GetValue(CurrentTimeBorderThicknessProperty); }
            set { SetValue(CurrentTimeBorderThicknessProperty, value); }
        }
        public SLControlLibrary.Resources.Common.Enumerations.TimeSlotsPerHour TimeSlotsPerHour
        {
            get { return (SLControlLibrary.Resources.Common.Enumerations.TimeSlotsPerHour)this.GetValue(TimeSlotsPerHourProperty); }
            set { this.SetValue(TimeSlotsPerHourProperty, value); }
        }
        public SLControlLibrary.Resources.Common.Enumerations.HoursPerDay HoursPerDay
        {
            get { return (SLControlLibrary.Resources.Common.Enumerations.HoursPerDay)this.GetValue(HoursPerDayProperty); }
            set { this.SetValue(HoursPerDayProperty, value); }
        }
        #endregion

        #region Dependency Events
        #region ContentBackground_Changed
        private static void ContentBackground_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucTimeSlots).OnContentBackground_Changed(e);
        }
        #endregion

        #region CurrentTimeBackground_Changed
        private static void CurrentTimeBackground_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucTimeSlots).OnCurrentTimeBackground_Changed(e);
        }
        #endregion

        #region ContentBorderBrush_Changed
        private static void ContentBorderBrush_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucTimeSlots).OnContentBorderBrush_Changed(e);
        }
        #endregion

        #region ContentBorderThickness_Changed
        private static void ContentBorderThickness_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucTimeSlots).OnContentBorderThickness_Changed(e);
        }
        #endregion

        #region CurrentTimeBorderBrush_Changed
        private static void CurrentTimeBorderBrush_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucTimeSlots).OnCurrentTimeBorderBrush_Changed(e);
        }
        #endregion

        #region CurrentTimeBorderThickness_Changed
        private static void CurrentTimeBorderThickness_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucTimeSlots).OnCurrentTimeBorderThickness_Changed(e);
        }
        #endregion

        #region TimeSlotsPerHour_Changed
        private static void TimeSlotsPerHour_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucTimeSlots).OnTimeSlotsPerHour_Changed(e);
        }
        #endregion

        #region HoursPerDay_Changed
        private static void HoursPerDay_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucTimeSlots).OnHoursPerDay_Changed(e);
        }
        #endregion
        #endregion

        #region Constructor
        public ucTimeSlots()
        {
            DefaultStyleKey = typeof(ucTimeSlots);
        }
        #endregion

        #region Methods
        #region OnApplyTemplate
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            PopulateTimeSlots();
        }
        #endregion

        #region PopulateTimeSlots
        private void PopulateTimeSlots()
        {
            TimeSlotsProvider _ts = new TimeSlotsProvider(this);
            this.ItemsSource = _ts.GetTimeSlots();
        }
        #endregion   
     
        #region OnContentBackground_Changed
        protected virtual void OnContentBackground_Changed(DependencyPropertyChangedEventArgs e)
        {
            ContentBackground = (Brush)e.NewValue;
            PopulateTimeSlots();
        }
        #endregion

        #region OnCurrentTimeBackground_Changed
        protected virtual void OnCurrentTimeBackground_Changed(DependencyPropertyChangedEventArgs e)
        {
            CurrentTimeBackground = (Brush)e.NewValue;
            PopulateTimeSlots();
        }
        #endregion

        #region OnContentBorderBrush_Changed
        protected virtual void OnContentBorderBrush_Changed(DependencyPropertyChangedEventArgs e)
        {
            ContentBorderBrush = (Brush)e.NewValue;
            PopulateTimeSlots();
        }
        #endregion

        #region OnContentBorderThickness_Changed
        protected virtual void OnContentBorderThickness_Changed(DependencyPropertyChangedEventArgs e)
        {
            ContentBorderThickness = (Thickness)e.NewValue;
            PopulateTimeSlots();
        }
        #endregion

        #region OnCurrentTimeBorderBrush_Changed
        protected virtual void OnCurrentTimeBorderBrush_Changed(DependencyPropertyChangedEventArgs e)
        {
            CurrentTimeBorderBrush = (Brush)e.NewValue;
            PopulateTimeSlots();
        }
        #endregion

        #region OnCurrentTimeBorderThickness_Changed
        protected virtual void OnCurrentTimeBorderThickness_Changed(DependencyPropertyChangedEventArgs e)
        {
            CurrentTimeBorderThickness = (Thickness)e.NewValue;
            PopulateTimeSlots();
        }
        #endregion

        #region OnTimeSlotsPerHour_Changed
        protected virtual void OnTimeSlotsPerHour_Changed(DependencyPropertyChangedEventArgs e)
        {
            TimeSlotsPerHour = (SLControlLibrary.Resources.Common.Enumerations.TimeSlotsPerHour)e.NewValue;
            PopulateTimeSlots();
        }
        #endregion

        #region OnHoursPerDay_Changed
        protected virtual void OnHoursPerDay_Changed(DependencyPropertyChangedEventArgs e)
        {
            HoursPerDay = (SLControlLibrary.Resources.Common.Enumerations.HoursPerDay)e.NewValue;
            PopulateTimeSlots();
        }
        #endregion
        #endregion        
    }
}
